/**
 * Created by TianJing on 2017/3/22.
 */
var storeId=common.getQueryString("storeId");
var $form=$("form");
var $companyList=$("#company-list");
var $searchCompanyInput=$(".search-company");
renderPage();
window.formObject = $form.submit(function() {
    var data = common.formToJson($(this));
    $.post(window.globalHost + common.storeUpdatePort, data).success(function(data) {
        layer.alert(data.res.msg);
        if ("0" == data.code) {
            //如果更新成功，重新渲染页面
            renderPage();
        }
    });
    return false;
});
function renderPage() {
    $.post(window.globalHost+common.storeInfoPort,{id:storeId}).success(function (data) {
        var record=common.transformData(data);
        common.initInputByName(record);
    });
    searchList.createDataListByInput({
        searchInput: $searchCompanyInput,
        searchInputId: $("#companyId"),
        dataListPanel:$companyList,
        listUrl:window.globalHost+common.companyListPort
    });
}
myLabel.addLabel(function () {
    var sendData={};
    common.openTempDialog({
        title:"添加门店标签",
        area:['640px', '200px'],
        content:myLabel.storeContent,
        sendData:sendData,
        FailedMsg:"请输入门店的标签名",
        contentOnLoad:function (layerDocument) {
            //弹窗内控件加载初始化
        },
        beforeSend:function (layerDocument) {
            var input=layerDocument.find("input");
            sendData.storeLabelName=input.val();
            return input.val();
        },
        resOk:function () {
            myLabel.labelList.append('<li class="btn">'+sendData.storeLabelName+'<i>x</i></li>')
        }
    });
});
myLabel.removeLabel();